package com.cn.wanxi.servlet;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.VO.ReusltModel;
import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.model.NewsModel;
import com.cn.wanxi.model.ProductModel;
import com.cn.wanxi.service.CompanyService;
import com.cn.wanxi.service.NavService;
import com.cn.wanxi.service.NewsServcie;
import com.cn.wanxi.service.ProductService;
import com.cn.wanxi.service.impl.CompanyServiceImpl;
import com.cn.wanxi.service.impl.NavServiceImpl;
import com.cn.wanxi.service.impl.NewsServiceImpl;
import com.cn.wanxi.service.impl.ProductServiceImpl;
import com.cn.wanxi.util.HomeEnum;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 六大步骤
 * 1.乱码
 * 2.得到前端数据
 * 3.封装model
 * 4.调用服务逻辑层
 * 5.得到返回的数据
 * 6.返回数据到前端
 */
@WebServlet("/topFoot")
public class TopFootServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //     1.乱码处理
        req.setCharacterEncoding("UTF-8");//前端提交数据到后台
        resp.setCharacterEncoding("UTF-8");//后台提交数据到前端

        ReusltModel reusltModel = new ReusltModel();
//        得到公司信息
        CompanyService companyService = new CompanyServiceImpl();
        CompanyModel companyModel = companyService.getCompanyModel();
        reusltModel.setCompanyModel(companyModel);


//        得到导航信息
        NavService navService = new NavServiceImpl();
        List<NavModel> navModelList = navService.getNavModelList();
        reusltModel.setNavModelList(navModelList);

        resp.getWriter().println(JSONObject.toJSONString(reusltModel));
    }
}
